//
//  LaiDianCell.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/11/8.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "LaiDianCell.h"

@implementation LaiDianCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self createUI];
        _orangeLab = [[UILabel alloc] initWithFrame:CGRectMake(2, 8, 3,60)];
        _orangeLab.backgroundColor = OverColor;
        [self addSubview:_orangeLab];
        //图片
        _peopleImg = [[UIImageView alloc] init];
        // _peopleImg.backgroundColor = [UIColor redColor];
        _peopleImg.image = [UIImage imageNamed:@"huinvshi"];
        [self addSubview:_peopleImg];
        [_peopleImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(16, 16));
            make.left.equalTo(_orangeLab.mas_right).offset(8);
            make.top.equalTo(self.mas_top).offset(9);
        }];
        //客户姓名
        _nameLab = [[UILabel alloc] init];
        _nameLab.textColor = OverColor;
        _nameLab.font = [UIFont systemFontOfSize:14];
        _nameLab.text = @"司徒静";
        [self addSubview:_nameLab];
        [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(60, 15));
            make.left.equalTo(_peopleImg.mas_right).offset(8);
            make.top.equalTo(self.mas_top).offset(12);
        }];
        
        //性别
        _sexLab = [[UILabel alloc] init];
        _sexLab.text = @"女 |";
        _sexLab.textColor = [UIColor blackColor];
        _sexLab.font = [UIFont systemFontOfSize:12];
        [self addSubview:_sexLab];
        [_sexLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(20, 15));
            make.left.equalTo(_nameLab.mas_right).offset(20);
            make.top.equalTo(self.mas_top).offset(12);
        }];
        
        
        //类别
        _leiLab= [[UILabel alloc] init];
        _leiLab.text = @"B类";
        _leiLab.textColor = [UIColor blackColor];
        _leiLab.font = [UIFont systemFontOfSize:12];
        [self addSubview:_leiLab];
        [_leiLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(30, 15));
            make.left.equalTo(_sexLab.mas_right).offset(10);
            make.top.equalTo(self.mas_top).offset(12);
        }];
        
        //成交状态
        _typeLab = [[UILabel alloc] init];
        _typeLab.textColor = [UIColor blackColor];
        _typeLab.font = [UIFont systemFontOfSize:12];
        [self addSubview:_typeLab];
        [_typeLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(80, 15));
            make.left.equalTo(_leiLab.mas_right).offset(10);
            make.top.equalTo(self.mas_top).offset(12);
        }];
        
        
        
        
        //首次来访
        _firstLab = [[UILabel alloc] init];
        //  _firstLab.text = @"首次来访 | 2017-08-31";
        _firstLab.textColor = [UIColor grayColor];
        _firstLab.font = [UIFont systemFontOfSize:10];
        [self addSubview:_firstLab];
        [_firstLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(120, 15));
            make.left.equalTo(_orangeLab.mas_right).offset(8);
            make.top.equalTo(self.mas_top).offset(32);
        }];
        //        _callLab = [[UILabel alloc] init];
        //       // _callLab.text = @"首次来电 | 2017-08-31";
        //        _callLab.textColor = [UIColor grayColor];
        //        _callLab.font = [UIFont systemFontOfSize:10];
        //        [self addSubview:_callLab];
        //        [_callLab mas_makeConstraints:^(MASConstraintMaker *make) {
        //            make.size.mas_equalTo(CGSizeMake(120, 15));
        //            make.left.equalTo(_orangeLab.mas_right).offset(8);
        //            make.top.equalTo(self.mas_top).offset(32);
        //        }];
        
        //上次跟进
        _shangLab = [[UILabel alloc] init];
        _shangLab.text = @"上次跟进 | 2017-09-10";
        _shangLab.textColor = [UIColor grayColor];
        _shangLab.font = [UIFont systemFontOfSize:10];
        [self addSubview:_shangLab];
        [_shangLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(120, 15));
            make.left.equalTo(_orangeLab.mas_right).offset(8);
            make.top.equalTo(self.mas_top).offset(49);
        }];
        
        //备注
        _remarkLab = [[UILabel alloc] init];
        _remarkLab.text = @"下周抽时间来看看具体情况";
        _remarkLab.textColor = [UIColor grayColor];
        _remarkLab.font = [UIFont systemFontOfSize:10];
        _remarkLab.numberOfLines = 0;
        [self addSubview:_remarkLab];
        [_remarkLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(160, 45));
            make.left.equalTo(_shangLab.mas_right).offset(10);
            make.top.equalTo(self.mas_top).offset(22);
        }];
        
        //电话
        _callBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        // _callBtn.backgroundColor = [UIColor orangeColor];
        _callBtn.layer.cornerRadius = 20;
        _callBtn.userInteractionEnabled = NO;
        [_callBtn setImage:[UIImage imageNamed:@"dianhuatubiao"] forState:0];
//        [_callBtn addTarget:self action:@selector(callPhoneBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_callBtn];
        [_callBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_offset(40);
            make.right.equalTo(self.mas_right).offset(-20);
            make.top.equalTo(self.mas_top).offset(15);
        }];
        
        //电话
        _callUpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_callUpBtn addTarget:self action:@selector(callPhoneBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_callUpBtn];
        [_callUpBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_offset(70);
            make.right.equalTo(self.mas_right).offset(0);
            make.top.equalTo(self.mas_top).offset(0);
        }];
        
        _NumPhone = [[UILabel alloc] init];
    }
    return self;
}


-(void)setUpVisitCellWithImg:(NSString *)_img withName:(NSString *)_name withSex:(NSString *)_sex withFen:(NSString *)_fen withFirstVisit:(NSString *)_first withGen:(NSString *)_gen withBei:(NSString *)_bei withPhone:(NSString *)_phone withChengJiaoState:(NSString *)_state withCallStr:(NSString *)_call
{
    _sexLab.text = _sex;
    if ([_sex isEqualToString:@"女"]) {
        
        _peopleImg.image = [UIImage imageNamed:@"huinvshi"];
        //_peopleImg.image = _img;
    }
    else
    {
        _peopleImg.image = [UIImage imageNamed:@"nanshihui"];
        // _peopleImg.image = _img;
    }
    _nameLab.text = _name;
    _leiLab.text = _fen;
    _sexLab.text = [NSString stringWithFormat:@"%@ |",_sex];
    _firstLab.text = [NSString stringWithFormat:@"首次来电 | %@",_first];
    _shangLab.text = [NSString stringWithFormat:@"上次跟进 | %@",_gen];
    _remarkLab.text = _bei;
    _NumPhone.text = _phone;
    _typeLab.text = _state;
    
    //如果是来电上边那个是nill
    // _callLab.text = [NSString stringWithFormat:@"首次来电 | %@",_call];
}


//重点在这里
- (void)createUI{
    //创建一个UIView比self.contentView小一圈
    self.bgView  = [[UIView alloc] initWithFrame:CGRectMake(0,5, [[UIScreen mainScreen] bounds].size.width, 64)];
    self.bgView.backgroundColor = [UIColor whiteColor];
    //给bgView边框设置阴影
    self.bgView.layer.shadowOffset = CGSizeMake(2,2);
    self.bgView.layer.shadowOpacity = 0.8;
    self.bgView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
    [self.contentView addSubview:self.bgView];
}
-(void)callPhoneBtnClick:(UIButton *)btn
{
    self.userInteractionEnabled = NO;
    btn.userInteractionEnabled = NO;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        btn.userInteractionEnabled = YES;
        self.userInteractionEnabled = YES;
    });
    
    NSString *phoneStr = _NumPhone.text;
    NSString *xlStr = [phoneStr stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",xlStr];
    UIWebView *callWebview = [[UIWebView alloc] init];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    [self addSubview:callWebview];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
